
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _extends2 = _interopRequireDefault(require('@babel/runtime/helpers/extends'));

const _utils = require('../../utils');

const _skuHelper = require('../utils/sku-helper');

const _createNamespace = (0, _utils.createNamespace)('sku-row-item');
const createComponent = _createNamespace[0];

const _default2 = createComponent({
  props: {
    skuValue: Object,
    skuKeyStr: String,
    skuEventBus: Object,
    selectedSku: Object,
    skuList: {
      type: Array,
      default: function _default() {
        return [];
      },
    },
  },
  computed: {
    choosable: function choosable() {
      return (0, _skuHelper.isSkuChoosable)(this.skuList, this.selectedSku, {
        key: this.skuKeyStr,
        valueId: this.skuValue.id,
      });
    },
  },
  methods: {
    onSelect: function onSelect() {
      if (this.choosable) {
        this.skuEventBus.$emit('sku:select', (0, _extends2.default)({}, this.skuValue, {
          skuKeyStr: this.skuKeyStr,
        }));
      }
    },
  },
  render: function render() {
    const h = arguments[0];
    const choosed = this.skuValue.id === this.selectedSku[this.skuKeyStr];
    const imgUrl = this.skuValue.imgUrl || this.skuValue.img_url;
    return h('span', {
      class: ['van-sku-row__item', {
        'van-sku-row__item--active': choosed,
        'van-sku-row__item--disabled': !this.choosable,
      }],
      on: {
        click: this.onSelect,
      },
    }, [imgUrl && h('img', {
      class: 'van-sku-row__item-img',
      attrs: {
        src: imgUrl,
      },
    }), h('span', {
      class: 'van-sku-row__item-name',
    }, [this.skuValue.name])]);
  },
});

exports.default = _default2;
